<?php

namespace App\Pojo;

class ResponsePojo
{
    /**
     * 成功响应
     *
     * @param mixed $data 响应数据
     * @param string $message 响应消息
     * @param int $statusCode 响应状态码
     * @return \Illuminate\Http\JsonResponse
     */
    public static function success($statusCode = 200, $message = '操作成功',  $data = null)
    {
        return response()->json([
            'code' => $statusCode,
            'success' => true,
            'message' => $message,
            'data' => $data
        ]);
    }

    /**
     * 失败响应
     *
     * @param string $message 响应消息
     * @param int $statusCode 响应状态码
     * @param mixed $errors 错误信息
     * @return \Illuminate\Http\JsonResponse
     */
    public static function error($statusCode = 400, $message = '操作失败', $errors = null)
    {
        return response()->json([
            'code' => $statusCode,
            'success' => false,
            'message' => $message,
            'errors' => $errors
        ]);
    }
}    